<?php
/**
 * $Id:$
 * @author nuarharuha
 * @since 0.1
 * 
 */
 
define('DS',DIRECTORY_SEPARATOR);
/**
 * path to gallery directory;
 */
define('GALLERY_PATH','gallery'.DS);


function fix_path($path) {
    return str_replace('\\','/',$path);
}


function mt_list_gallery_image($type = 'index'){
    
    $items = new RecursiveDirectoryIterator(GALLERY_PATH);
    
    switch($type):
        case 'index':
        
        foreach($items as $file) {
            
            /**
             * If directory 
             * Convert it to heading 
             */
            if ($file->isDir()){
                $album_title = $file->getFilename();
                $group_name = 'group';
                
                echo '<h2 class="dir-title"><small>Album</small> <span>'. $album_title.'</span></h2>'.PHP_EOL;
                foreach(new RecursiveDirectoryIterator($file) as $subfile) {
                    $uri = fix_path($subfile);
                    
                    echo '<p><a class="fancybox" rel="'.$group_name.'" href="'.$uri.'">';
                    echo '<img width="700" src="'.$uri.'" alt="'.basename($subfile).'"></a></p>'.PHP_EOL;
                }
            } else {
                echo '<img width="700" src="'.fix_path($file).'" alt="'.basename($file).'">'.PHP_EOL;
            }
        }
        break;
        
        /**
         * gallery has 2 image in a row
         */
        case 'gallery':
        
            foreach($items as $file) {
                if ($file->isDir()){
                    $album_title = $file->getFilename();
                    $group_name = 'group';
                    
                    echo '<h2 class="dir-title"><small>Album</small> <span>'. $album_title.'</span></h2>'.PHP_EOL;
                    
                    $i = 0;
                    foreach(new RecursiveDirectoryIterator($file) as $subfile) {
                        $uri = fix_path($subfile);
                        if ($i%2) { 
                            echo ''; }else{ echo '<p>'; }
                        echo '<a class="fancybox" rel="'.$group_name.'" href="'.$uri.'">';
                        echo '<img width="320" src="'.$uri.'" alt="'.basename($subfile).'"></a>'.PHP_EOL;
                        if ($i%2) { echo '</p>'; }
                        $i++;
                        echo '<!-- '.$i.' -->'.PHP_EOL;
                    }
                } else {
                    echo '<img width="320" src="'.fix_path($file).'" alt="'.basename($file).'">'.PHP_EOL;
                }
            }     
           
        break;    
    endswitch;
}

/**
 * html_header()
 * @param title 
 */ 

function html_header($title=""){
?>
<!DOCTYPE HTML>
<head>
	<meta charset="utf-8">
	<meta name="author" content="imanan kamila">    
    <meta name="description" content="Epi Ozir Photography">
    <meta name="google-site-verification" content="Ahv7XavcHcw-Wv2tDYxnlTWtrs7etri8Pdb5FPd6I7M" />
    
	<title><?php echo $title . ' Epi Ozir Photography'; ?></title>             
    <link rel="stylesheet" href="style.css"/>
    <link rel='stylesheet' href='http://fonts.googleapis.com/css?family=Oswald'>
    <link rel="stylesheet" href="http://demo.menestystech.com/portfolio-2/fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />
</head>
<?php      
}

/**
 * void html_navigation() 
 */ 
function navigation_menu(){
?>
    <script>    
        function safe_redirect(){
            if (window.location.host == "epiozir.com"){
                window.location.href = "http://epiozir.com/";
            } else {
                window.location.href = "http://demo.menestystech.com/portfolio-2/";
            }
        }
    </script>
    <div id="navigation">
    <a href="" onclick="safe_redirect();return false;">home</a><a href="photo-gallery">gallery</a><a href="about">about</a><a href="contact">contact us</a>
    </div>
<?php
}

/**
 * void html_footer() 
 */
function html_footer()
{
?>
<script>
function scroll(){
$('body,html').animate({
				scrollTop: 0
			}, 1600);
			return false;
}
</script>

<div id="footer"> 
    <p>&copy; Copyright 2012 <a href="#">Epi OZir</a>. All rights reserved.</p>
    <p><a href="#" onclick="scroll()">scroll to top</a></p>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>

<script type="text/javascript" src="http://demo.menestystech.com/portfolio-2/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<script type="text/javascript" src="scripts.js"></script>
<?php    
}
